package com.kawa.kemanage.controller.api;

import com.kawa.kemanage.entity.ViolatedContent;
import com.kawa.kemanage.service.ViolatedContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/api/violations")
public class ViolatedContentController {

    @Autowired
    private ViolatedContentService violatedContentService;

    @GetMapping
    public ResponseEntity<List<ViolatedContent>> list(
            @RequestParam(value = "contentId", required = false) String contentId,
            @RequestParam(value = "violationType", required = false) String violationType,
            @RequestParam(value = "handleStatus", required = false) String handleStatus,
            @RequestParam(value = "startDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
            @RequestParam(value = "endDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
    ) {
        List<ViolatedContent> list = violatedContentService.search(
                contentId,
                violationType,
                handleStatus,
                startDate,
                endDate
        );
        return new ResponseEntity<>(list, HttpStatus.OK);
    }

    @PostMapping("/handle/{id}")
    public ResponseEntity<String> markHandled(@PathVariable Long id) {
        violatedContentService.markAsHandled(id);
        return new ResponseEntity<>("处理成功", HttpStatus.OK);
    }
}
